import axios from "axios";

const baseApi = 'http://localhost:6284'
export const websocketUrl = 'ws://101.35.231.245:119/webSocket/'
//const baseApi = 'http://localhost:1073'
//export const websocketUrl = 'ws://localhost:1080/webSocket/'


/**
 * @Author 时啟轩
 * 登录页面
 */
//登录
export const signInPost = (phoneNum, password)=>axios.post(
    baseApi + '/sign/signInCheck',
    null,
    {
        params:{
            phoneNum: phoneNum,
            password: password
        },
        withCredentials: true
    }
)
//获取验证码
export const getPhoneCode = (phoneNum, mode)=>axios.post(
    baseApi + '/sign/getPhoneCode',
    null,
    {
        params:{
            phoneNum: phoneNum,
            mode: mode
        }
    }
)
//注册
export const signUpPost = (phoneNum, password, mode, code)=>axios.post(
    baseApi + '/sign/signUp',
    null,
    {
        params:{
            phoneNum: phoneNum,
            password: password,
            mode: mode,
            code: code,
        }
    }
)
//重设密码
export const resetPassword = (phoneNum, mode, code, newPassword)=> axios.post(
    baseApi + '/sign/resetPassword',
    null,
    {
        params:{
            phoneNum: phoneNum,
            mode: mode,
            code: code,
            newPassword: newPassword
        }
    }
)

/**
 * 自定义App信息
 */
export const getAppName = ()=>{
    return axios.get(baseApi+'/custom/appName')
}

export const getAppDetail = ()=>{
    return axios.get(baseApi+'/custom/appDetail')
}

export const getCollege = ()=>{
    return axios.get(baseApi+'/custom/collegeName')
}

export const getHelpContent = ()=>{
    return axios.get(baseApi+'/custom/helpContent')
}

/**
 * 商品
 */
//获取所有商品
export const getAllProducts = (startIndex, length)=>axios.get(
    baseApi+'/product/getAllProducts',
    {
        params:{
            startIndex: startIndex,
            length: length
        }
    }
)
//获取当前用户发布的商品
export const getProductsByOwnerId = (startIndex, length)=>axios.get(
    baseApi+'/product/getProductsByOwnerId',
    {
        params:{
            startIndex: startIndex,
            length: length
        },
        withCredentials: true
    }
)
//获取用户购物车内的商品
export const getUserCartProducts = ()=>axios.get(
    baseApi+'/cart/getCartProducts',
    {
        withCredentials: true
    }
)
//获取用户买到的商品
export const getUserBoughtProducts = ()=>axios.get(
    baseApi+'/purchase/purchaseProducts',
    {
        withCredentials: true
    }
)
//移出购物车
export const deleteFromCartApi = (productId)=>axios.post(
    baseApi+'/cart/deleteCart',
    null,
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)
//删除商品
export const deleteProductApi = (productId) =>axios.get(
    baseApi+'/product/deleteProductById',
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)
export const purchaseProduct = (productId)=> axios.post(
    baseApi + '/cart/purchaseProduct',
    null,
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)
//加入购物车
export const addCart = (productId)=> axios.post(
    baseApi + '/cart/addCart',
    null,
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)
//添加商品
export const uploadProductApi = (uploadData)=>axios.post(
    baseApi+'/product/uploadProduct',
    uploadData,
    {
        withCredentials: true
    }
)
//重新出售商品
export const resellApi = (productId)=>axios.post(
    baseApi + '/product/resell',
    null,
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)
//更新商品
export const updateProductApi = (product)=>axios.post(
    baseApi+'/product/updateProduct',
    product,
    {
        withCredentials: true
    }
)

/**
 * @Author 时啟轩
 * 消息
 */
//获取联系方式
export const getContactApi = (productId)=>axios.get(
    baseApi+'/purchase/getContact',
    {
        params:{
            productId: productId
        },
        withCredentials: true
    }
)



//获取所有对话
export const getAllDialogues = (token)=>axios.post(
    baseApi+'/message1080/dialogue/all/getAllDialogues',
    null,
    {
        headers:{
            Authorization:'Bearer '+token
        }
    }
)
//获取某对话所有消息
export const getAllMessages = (token, dialogueId)=>axios.post(
    baseApi+'/message1080/message/selectMessages',
    null,
    {
        params:{
            dialogueId:dialogueId
        },
        headers:{
            Authorization:'Bearer '+token
        }
    }
)
//存储httpsession
export const saveSession = (token, userId)=>axios.post(
    baseApi+'/message1080/saveSession',
    null,
    {
        params:{
            userId:userId
        },
        headers:{
            Authorization:'Bearer '+token
        }
    }
)
//消息图片接口
export const messageImgUrl = baseApi + '/hwobs9373/obs/getMessagePicture'

/**
 * 通用
 */
//上传图片
export const uploadImgApi = (formData)=>axios.post(
    baseApi+'/file/defaultUpLoadFile',
    formData,
    {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    }
)